@use "sass:map";

.content-wrapper {
  width: 100%;

  .container-fluid {
    --container-padding-x: #{$container-margin};
    padding: 0 var(--container-padding-x);

    @include gl-container-width-up(xl, panel) {
      --container-padding-x: #{$container-margin-xl};
    }

    &.container-blank {
      background: none;
      padding: 0;
      border: 0;
    }
  }
}

.page-initialised  .content-wrapper {
  @apply gl-transition-padding;
}

.right-sidebar-collapsed {
  padding-right: 0;

  &:not(.is-merge-request) {
    @include media-breakpoint-up(sm) {
      @apply gl-border-l;

      &:not(.wiki-sidebar):not(.build-sidebar):not(.issuable-bulk-update-sidebar) .content-wrapper {
        padding-right: $right-sidebar-collapsed-width;
      }
    }
  }

  .sidebar-collapsed-icon {
    .btn {
      @apply gl-bg-subtle;
    }

    &:not(.disabled) {
      cursor: pointer;
    }

    svg {
      width: $gl-padding;
      height: $gl-padding;
    }
  }

  .right-sidebar-header {
    flex-wrap: wrap;
  }
}

.right-sidebar-expanded {
  padding-right: 0;
  z-index: $zindex-dropdown-menu;

  .right-sidebar-header {
    padding-block: $gl-spacing-scale-4;
    margin-left: 20px;
  }

  .inline-block {
    display: inline-block;
  }

  &.right-sidebar-merge-requests {
    width: $right-sidebar-width;

    @include gl-container-width-up(md, panel) {
      z-index: auto;
    }

    .shortcut-sidebar-dropdown-toggle {
      margin-right: 0 !important;
    }
  }

  @include media-breakpoint-only(sm) {
    &:not(.wiki-sidebar):not(.build-sidebar):not(.issuable-bulk-update-sidebar):not(.is-merge-request) .content-wrapper {
      padding-right: $right-sidebar-collapsed-width;
    }
  }

  &:not(.is-merge-request):not(.build-sidebar) {
    @include media-breakpoint-up(sm) {
      .content-wrapper {
        padding-right: $right-sidebar-width;
      }
    }
  }
}

.right-sidebar {
  &:where(.right-sidebar-expanded) {
    @apply gl-border-l;
  }

  &.right-sidebar-merge-requests {
    @include gl-container-width-up(lg, panel) {
      border-left: 0;
    }
  }
}

@mixin maintain-sidebar-dimensions {
  display: flex;
  flex-direction: column;
  width: $right-sidebar-width;
}

.issues-bulk-update.right-sidebar {
  @include maintain-sidebar-dimensions;
  width: 0;
  padding: 0;
  @apply gl-transition-width;

  &.right-sidebar-expanded {
    @include maintain-sidebar-dimensions;
    width: $right-sidebar-width;

    .issuable-sidebar-header {
      // matches `.top-area .nav-controls` for issuable index pages
      padding: 11px 0;
    }

    .block:last-of-type {
      border: 0;
    }
  }

  &.right-sidebar-collapsed {
    @include maintain-sidebar-dimensions;
    width: 0;
    padding: 0;

    .block {
      padding: 16px 0;
      width: 250px;
      @apply gl-border-b;
    }
  }

  .issuable-sidebar {
    padding: 0 3px;
  }

  .block {
    border-bottom: 0;
    padding-top: 0;
  }
}

.issuable-sidebar .labels {
  .value.dont-hide ~ .selectbox {
    padding-top: $gl-padding-8;
  }

  // This is for sidebar components using gl-button for the Edit button to be consistent with the
  // rest of the sidebar, and could be removed once the sidebar has been fully converted to use
  // gitlab-ui components.
  .title .gl-button {
    font-weight: $gl-font-weight-bold;

    .gl-button {
      @apply gl-text-default;
    }
  }
}

.pikaday-container {
  .pika-single {
    margin-top: 2px;
    width: 250px;
  }

  .dropdown-menu-toggle {
    line-height: 20px;
  }
}

.sidebar-collapsed-icon {
  font-size: 12px;
}

.toggle-right-sidebar-button {
  @apply gl-transition-width;
  height: $toggle-sidebar-height;
  padding: 0 $gl-padding;
  @apply gl-bg-subtle;
  border: 0;
  @apply gl-text-subtle;
  display: flex;
  align-items: center;
  @apply gl-border-b;

  &:hover {
    @apply gl-bg-strong;
    @apply gl-text-default;
  }
}

.edit-link {
  margin-right: -$gl-spacing-scale-2;
}

.issuable-sidebar.is-merge-request .edit-link {
  margin-right: 0;
}

.assignee-grid {
  grid-template-areas: 'attention user';
  grid-template-columns: min-content 1fr;
}

.reviewer-grid {
  grid-template-areas: 'user approval rerequest remove';
  grid-template-columns: 1fr;
}

.reviewers-dropdown .gl-new-dropdown-panel {
  min-width: $right-sidebar-width - $gl-padding;
}

.merge-request-approved-icon {
  animation: approval-animate 350ms ease-in;
}

@include keyframes(approval-animate) {
  0% {
    transform: scale(0);
  }

  75% {
    transform: scale(1.4);
  }

  100% {
    transform: scale(1);
  }
}

.assignee-grid,
.reviewer-grid {
  [data-css-area='user'] {
    grid-area: user;
  }
}

@mixin right-sidebar {
  position: fixed;
  bottom: $calc-application-footer-height;
  right: 0;
  @apply gl-bg-default;
  z-index: 200;
  overflow: hidden;
  @apply gl-transition-width;
}

.right-sidebar {
  &:not(.right-sidebar-merge-requests) {
    @include right-sidebar;
    top: $calc-application-header-height;

    @include gl-container-width-down(lg, panel) {
      z-index: 251;
    }
  }

  &.right-sidebar-merge-requests {
    @include gl-container-width-down(lg, panel) {
      @include right-sidebar;
      top: $calc-application-bars-height;
      z-index: 251;
    }

    @include gl-container-width-down(md, panel) {
      top: $calc-application-header-height;
    }
  }

  a:not(.btn) {
    color: inherit;

    &:hover {
      @apply gl-text-link;
    }
  }

  .gl-label .gl-label-link:hover {
    color: inherit;
  }

  .btn-link {
    color: inherit;
  }

  .gutter-toggle {
    display: flex;
    align-items: center;
    margin-left: 20px;
    padding: 4px;
    border-radius: 4px;
    height: 24px;

    &:hover {
      @apply gl-text-default;
      @apply gl-bg-strong;
    }

    &:hover,
    &:focus {
      text-decoration: none;
    }
  }

  &.right-sidebar-merge-requests {
    .block,
    .sidebar-contained-width,
    .issuable-sidebar-header {
      width: 100%;
    }

    .block {
      @include gl-container-width-up(lg, panel) {
        padding: $gl-spacing-scale-4 0 $gl-spacing-scale-5;
      }

      &.participants {
        border-bottom: 0;
      }
    }
  }

  .block,
  .sidebar-contained-width,
  .issuable-sidebar-header {
    @include clearfix;
    padding: $gl-spacing-scale-4 0 $gl-spacing-scale-5;
    @apply gl-border-b;
    @apply gl-border-subtle;
    // This prevents the mess when resizing the sidebar
    // of elements repositioning themselves..
    width: $right-sidebar-inner-width;
    // --

    &:last-child {
      border: 0;
    }

    &.assignee {
      .author-link {
        display: block;
        position: relative;

        &:hover {
          .author {
            text-decoration: underline;
          }
        }
      }
    }

    &.time-tracking,
    &.participants,
    &.subscriptions,
    &.with-sub-blocks {
      padding-top: $gl-spacing-scale-5;
    }
  }

  .title {
    @apply gl-text-default;
    line-height: $gl-line-height-20;

    .avatar {
      margin-left: 0;
    }
  }

  .selectbox {
    display: none;

    &.show {
      display: block;
    }
  }

  .issuable-sidebar {
    height: 100%;

    &:not(.is-merge-request) {
      overflow-y: scroll;
      overflow-x: hidden;
      -webkit-overflow-scrolling: touch;
    }

    &.is-merge-request {
      @include gl-container-width-down(md, panel) {
        overflow-y: scroll;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
      }
    }
  }

  &.right-sidebar-expanded {
    &:not(.right-sidebar-merge-requests) {
      width: $right-sidebar-width;
    }

    .issuable-sidebar-header {
      padding-top: $gl-spacing-scale-5;
      padding-bottom: $gl-spacing-scale-5;
    }

    .value {
      line-height: 1;
    }

    .issuable-sidebar {
      padding: 0 20px;

      &.is-merge-request {
        @include gl-container-width-up(lg, panel) {
          padding: 0;

          .issuable-context-form {
            top: calc(#{$calc-application-header-height} + #{$mr-sticky-header-height});
            height: calc(#{$calc-application-viewport-height} - #{$mr-sticky-header-height});
            position: sticky;
            padding: 0 $gl-spacing-scale-3;
            margin-bottom: calc((#{$content-wrapper-padding} * -1));
            overflow-y: auto;
            overscroll-behavior: contain;
          }
        }
      }
    }

    &:not(.boards-sidebar):not([data-signed-in]):not([data-always-show-toggle]) {
      .issuable-sidebar-header {
        display: none;
      }
    }

    .light {
      font-weight: $gl-font-weight-normal;
    }

    .no-value {
      @apply gl-text-subtle;
    }

    .sidebar-collapsed-icon {
      display: none;
    }

    .gutter-toggle {
      text-align: center;
    }

    .title .gutter-toggle {
      margin-top: 0;
    }

    .assignee .user-list .avatar {
      margin: 0;
    }

    .hide-expanded {
      display: none;
    }
  }

  &.right-sidebar-collapsed {
    /* Extra small devices (phones, less than 768px) */
    display: none;
    /* Small devices (tablets, 768px and up) */

    &:not(.right-sidebar-merge-requests) {
      @include gl-container-width-up(sm, panel) {
        display: block;
      }
    }

    &.right-sidebar-merge-requests {
      @include gl-container-width-up(lg, panel) {
        display: block;
      }
    }

    width: $right-sidebar-collapsed-width;
    padding: 0;

    .block,
    .sidebar-contained-width,
    .issuable-sidebar-header {
      width: $right-sidebar-collapsed-width - 2px;
      padding: 0;
      border-bottom: 0;
      overflow: hidden;
    }

    .block,
    .gutter-toggle,
    .sidebar-collapsed-container {
      &.with-sub-blocks .sub-block:hover,
      &:not(.with-sub-blocks):hover {
        background-color: $gray-100;
      }
    }

    .participants {
      @apply gl-border-b;
    }

    .hide-collapsed {
      display: none;
    }

    .gutter-toggle {
      width: 100%;
      height: $sidebar-toggle-height;
      margin-top: 0;
      margin-left: 0;
      @apply gl-border-b #{!important};
      border-radius: 0;
    }

    a.gutter-toggle {
      display: flex;
      justify-content: center;
      flex-direction: column;
      text-align: center;
    }

    .merge-icon {
      height: 12px;
      width: 12px;
      bottom: -5px;
      right: 4px;
    }

    .sidebar-collapsed-icon {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: $sidebar-toggle-height;
      text-align: center;
      @apply gl-text-subtle;

      > svg {
        @apply gl-fill-icon-subtle;
      }

      &:hover:not(.disabled),
      &:hover .todo-undone {
        @apply gl-text-default;

        > svg {
          @apply gl-fill-icon-default;
        }
      }

      .todo-undone {
        color: $blue-600;
        fill: $blue-600;
      }

      .author {
        display: none;
      }

      &.multiple-users {
        display: flex;
        justify-content: center;
      }
    }

    .sidebar-avatar-counter {
      width: 24px;
      height: 24px;
      border-radius: 12px;

      ~.merge-icon {
        bottom: 0;
      }
    }

    .sidebar-collapsed-user {
      padding-bottom: 0;

      .author-link {
        padding-left: 0;

        .avatar {
          position: static;
          margin: 0;
        }
      }
    }

    .issuable-header-btn {
      display: none;
    }

    .multiple-users {
      .btn-link {
        padding: 0;
        border: 0;

        .avatar {
          margin: 0;
        }
      }

      .btn-link:first-child {
        position: absolute;
        left: 10px;
        z-index: 1;
      }

      .btn-link:last-child {
        position: absolute;
        right: 10px;

        &:hover {
          text-decoration: none;
        }
      }
    }

    .milestone-title span,
    .collapse-truncated-title {
      @include str-truncated(100%);
      display: block;
      margin: 0 4px;
    }
  }

  .dropdown-menu-toggle {
    width: 100%;
    padding-top: 6px;
  }

  .dropdown-menu {
    width: 100%;

    /*
     * Overwrite hover style for dropdown items, so that they are not blue
     * This should be removed during dev of https://gitlab.com/gitlab-org/gitlab-foss/issues/44040
     */
    li a {
      &:hover,
      &:active,
      &:focus,
      &.is-focused {
        @include dropdown-item-hover;
        background-color: transparent;
      }
    }

  }
}

.issuable-show-labels {
  .gl-label {
    margin-bottom: $gl-spacing-scale-2;
    margin-right: $gl-spacing-scale-2;
  }

  a {
    display: inline-block;

    .color-label {
      padding: 4px $grid-size;
      border-radius: $label-border-radius;
      margin-right: 4px;
      margin-bottom: 4px;
    }

    &:hover .color-label {
      text-decoration: underline;
    }
  }

  &.has-labels {
    // this font size is a fix to
    // prevent unintended spacing between labels
    // which shows up when rendering markup has white-space
    // characters present.
    // see: https://css-tricks.com/fighting-the-space-between-inline-block-elements/#article-header-id-3
    font-size: 0;
    margin-bottom: -5px;
  }
}

.reviewer-merge-icon,
.assignee .merge-icon,
.reviewer .merge-icon {
  color: var(--gl-status-warning-icon-color);
  position: absolute;
  bottom: -3px;
  right: -3px;
  filter: drop-shadow(1px 0 0 var(--gl-background-color-default))
          drop-shadow(-1px 0 0 var(--gl-background-color-default))
          drop-shadow(0 -1px 0 var(--gl-background-color-default))
          drop-shadow(0 1px 0 var(--gl-background-color-default));
}

.sidebar-help-wrap {
  .sidebar-help-state {
    margin: 16px -20px -20px;
    padding: 16px 20px;
  }

  // These are composite classes for use with Vue Transition
  // https://vuejs.org/guide/built-ins/transition
  .help-state-toggle-enter-active {
    transition: all 0.8s ease;
  }

  .help-state-toggle-leave-active {
    transition: all 0.5s ease;
  }

  .help-state-toggle-enter,
  .help-state-toggle-leave-active {
    opacity: 0;
  }
}

.time-tracker {
  .sidebar-collapsed-icon {
    > .stopwatch-svg {
      display: inline-block;
    }

    svg {
      width: 16px;
      height: 16px;
      @apply gl-fill-icon-subtle;
    }

    &:hover svg {
      @apply gl-fill-icon-default;
    }
  }

  .compare-meter {
    &.over_estimate {
      .time-remaining,
      .compare-value.spent {
        @apply gl-text-danger;
      }
    }
  }

  .compare-display-container {
    font-size: 13px;
  }
}

.duo-agent-platform-sidebar-widget {
  @apply gl-mt-3;
  @apply gl-mx-3;
  @apply gl-p-4;
  @apply gl-bg-default;
  @apply gl-rounded-base;
}

:where(.application-chrome) {
  .duo-agent-platform-sidebar-widget {
    @apply gl-mt-4;

    border: solid 2px transparent;
    border-radius: 1rem;
    background:
      linear-gradient(var(--gl-background-color-default), var(--gl-background-color-default)) padding-box,
      linear-gradient(200deg, var(--_shade-4), var(--_shade-3)) border-box;
  }
}
